package com.hsc.yalebao.tabMine;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hsc.yalebao.base.ActivityStack;
import com.hsc.yalebao.base.BaseActivity;
import com.hsc.yalebao.base.CustomApplication;
import com.hsc.yalebao.base.MainActivity;
import com.hsc.yalebao.http.AppConstants;
import com.hsc.yalebao.http.RequestNet;
import com.hsc.yalebao.model.FindPasswordBean;
import com.hsc.yalebao.model.TokenModel;
import com.hsc.yalebao.model.VeryPasswordBean;
import com.hsc.yalebao.tools.SMSBroadcastReceiver;
import com.hsc.yalebao.tools.SMSBroadcastReceiver.MessageListener;
import com.hsc.yalebao.tools.UiUtil;
import com.hsc.yalebao.weight.LogUtils;
import com.hsc.yalebao.weight.MyDialog1;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;

import okhttp3.Call;

public class ForgetLoginPwdActivity extends BaseActivity {
    private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
    private String TAG = "ForgetLoginPwdActivity";
    private Context context;
    private EditText edit_new_loginpwd;
    private EditText edit_user_phone_no;
    private EditText edit_user_veriy_code;
    private Button get_veriycode;
    private Handler handler = new Handler() {
        public void handleMessage(Message paramAnonymousMessage) {
            super.handleMessage(paramAnonymousMessage);
            switch (paramAnonymousMessage.what) {
                default:
                    return;
                case 0:
                    ForgetLoginPwdActivity.this.isPause = false;
                    int i = paramAnonymousMessage.arg1;
                    ForgetLoginPwdActivity.this.get_veriycode.setText(i + "s");
                    ForgetLoginPwdActivity.this.get_veriycode.setBackgroundResource(2130837970);
                    ForgetLoginPwdActivity.this.get_veriycode.setEnabled(false);
                    return;
                case 1:
            }
            ForgetLoginPwdActivity.this.isPause = true;
            ForgetLoginPwdActivity.this.timerRecord = 120;
            ForgetLoginPwdActivity.this.get_veriycode.setText("重新获取");
            ForgetLoginPwdActivity.this.get_veriycode.setBackgroundResource(2130837969);
            ForgetLoginPwdActivity.this.get_veriycode.setEnabled(true);
        }
    };
    private ImageView img_sure;
    private boolean isPause = true;
    private ImageView iv_title_right;
    private String mAction = "";
    private SMSBroadcastReceiver mSMSBroadcastReceiver;
    private MyDialog1 myDialog1;
    View.OnClickListener onClickListener = new View.OnClickListener() {
        public void onClick(View paramAnonymousView) {
            switch (paramAnonymousView.getId()) {
                case 2131099704:
                default:
                    return;
                case 2131099699:
                    ForgetLoginPwdActivity.this.closeWindowSoftInput(ForgetLoginPwdActivity.this.user_name);
                    ForgetLoginPwdActivity.this.closeWindowSoftInput(ForgetLoginPwdActivity.this.edit_user_phone_no);
                    ForgetLoginPwdActivity.this.closeWindowSoftInput(ForgetLoginPwdActivity.this.edit_user_veriy_code);
                    ForgetLoginPwdActivity.this.closeWindowSoftInput(ForgetLoginPwdActivity.this.edit_new_loginpwd);
                    CustomApplication.app.finishActivity(ForgetLoginPwdActivity.this);
                    return;
                case 2131099755:
                    String str1 = ForgetLoginPwdActivity.this.edit_user_phone_no.getText().toString().trim();
                    String str2 = ForgetLoginPwdActivity.this.user_name.getText().toString();
                    if ("".equals(str2))
                        UiUtil.showToast(ForgetLoginPwdActivity.this.context, "请输入您的用户名");
                    if (str1.isEmpty())
                        UiUtil.showToast(ForgetLoginPwdActivity.this.context, "手机号不能为空");
                    if (!UiUtil.isMobileNO(str1)) {
                        UiUtil.showToast(ForgetLoginPwdActivity.this.context, "请检查您的手机号");
                        return;
                    }
                    ForgetLoginPwdActivity.this.getveriycode(str1, str2);
                    UiUtil.showToast(ForgetLoginPwdActivity.this.context, "请稍等");
                    return;
                case 2131099756:
            }
            AppConstants.NO_LOGIN_TOKEN = "";
            ForgetLoginPwdActivity.this.checkoutdata();
        }
    };
    private TextWatcher textWatcher = new TextWatcher() {
        public void afterTextChanged(Editable paramAnonymousEditable) {
        }

        public void beforeTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {
        }

        public void onTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {
            if (ForgetLoginPwdActivity.this.edit_user_phone_no.getText().toString().length() != 11) {
                ForgetLoginPwdActivity.this.get_veriycode.setBackgroundResource(2130837970);
                ForgetLoginPwdActivity.this.get_veriycode.setEnabled(false);
                return;
            }
            ForgetLoginPwdActivity.this.get_veriycode.setBackgroundResource(2130837554);
            ForgetLoginPwdActivity.this.get_veriycode.setEnabled(true);
        }
    };
    private Timer timer = new Timer();
    private int timerRecord = 120;
    private EditText user_name;
    private View view_title;

    private void ChangeMobile(String paramString1, String paramString2, String paramString3, String paramString4) {
        HashMap localHashMap = new HashMap();
        localHashMap.put("user_name", paramString1);
        localHashMap.put("newpassword", paramString2);
        localHashMap.put("mobile", paramString3);
        localHashMap.put("code", paramString4);
        LogUtils.d(this.TAG, "URL:" + AppConstants.URL_GET_FINDPASSWORD);
        setSureBtnIsEnable(false);
        showLoadingDialog();
        this.mAction = "1";
        if (AppConstants.NO_LOGIN_TOKEN.equals("")) {
            getToken();
            return;
        }
        RequestNet.get(this.context, AppConstants.URL_GET_FINDPASSWORD, localHashMap, new StringCallback() {
            public void onError(Call paramAnonymousCall, Exception paramAnonymousException) {
                ForgetLoginPwdActivity.this.dismissLoadingDialog();
                ForgetLoginPwdActivity.this.setSureBtnIsEnable(true);
                LogUtils.e(ForgetLoginPwdActivity.this.TAG, "请求失败,:" + paramAnonymousException);
            }

            public void onResponse(String paramAnonymousString) {
                LogUtils.d(ForgetLoginPwdActivity.this.TAG, "findPasswordBean数据" + paramAnonymousString);
                ForgetLoginPwdActivity.this.setSureBtnIsEnable(true);
                ForgetLoginPwdActivity.this.dismissLoadingDialog();
                if (UiUtil.IsValueEmpty(paramAnonymousString))
                    LogUtils.d(ForgetLoginPwdActivity.this.TAG, "findPasswordBean:" + paramAnonymousString);
                FindPasswordBean localFindPasswordBean;
                do {
                    return;
                    Gson localGson = new Gson();
                    try {
                        localFindPasswordBean = (FindPasswordBean) localGson.fromJson(paramAnonymousString, FindPasswordBean.class);
                        if (localFindPasswordBean == null) {
                            LogUtils.e(ForgetLoginPwdActivity.this.TAG, "getVeriyCodeBean == null，绑定失败");
                            return;
                        }
                    } catch (Exception localException) {
                        while (true) {
                            localException.printStackTrace();
                            localFindPasswordBean = null;
                        }
                        if (localFindPasswordBean.getFlag() == 0) {
                            ForgetLoginPwdActivity.this.ShowDialog1(localFindPasswordBean.getMsg());
                            return;
                        }
                        if (localFindPasswordBean.getFlag() == -2) {
                            ForgetLoginPwdActivity.this.showDownWireDialog();
                            return;
                        }
                        if (localFindPasswordBean.getFlag() == -3) {
                            ForgetLoginPwdActivity.this.ShowFengjinDialog();
                            return;
                        }
                        if (localFindPasswordBean.getFlag() == -4) {
                            ForgetLoginPwdActivity.activityStack.backToMain(MainActivity.class, ForgetLoginPwdActivity.this.context);
                            return;
                        }
                    }
                }
                while (localFindPasswordBean.getFlag() != 1);
                ForgetLoginPwdActivity.this.myDialog1.setMessage(localFindPasswordBean.getMsg());
                ForgetLoginPwdActivity.this.myDialog1.show();
                ForgetLoginPwdActivity.this.myDialog1.btn_confirm.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View paramAnonymous2View) {
                        ForgetLoginPwdActivity.this.myDialog1.dismiss();
                        ForgetLoginPwdActivity.this.edit_user_phone_no.setText("");
                        ForgetLoginPwdActivity.this.edit_user_veriy_code.setText("");
                        ForgetLoginPwdActivity.this.edit_new_loginpwd.setText("");
                        ForgetLoginPwdActivity.this.user_name.setText("");
                        CustomApplication.app.finishActivity(ForgetLoginPwdActivity.this);
                    }
                });
            }
        });
    }

    private void checkoutdata() {
        String str1 = this.edit_user_veriy_code.getText().toString();
        String str2 = this.edit_new_loginpwd.getText().toString();
        String str3 = this.edit_user_phone_no.getText().toString().trim();
        String str4 = this.user_name.getText().toString();
        if ("".equals(str4)) {
            UiUtil.showToast(this.context, "请输入您的用户名");
            return;
        }
        if (str3.isEmpty()) {
            UiUtil.showToast(this.context, "手机号不能为空");
            return;
        }
        if (!UiUtil.isMobileNO(str3)) {
            UiUtil.showToast(this.context, "请检查您的手机号");
            return;
        }
        if ("".equals(str1)) {
            UiUtil.showToast(this.context, "请输入您的验证码");
            return;
        }
        if (str1.length() != 6) {
            UiUtil.showToast(this.context, "请检查您的验证码");
            return;
        }
        if ("".equals(str2)) {
            UiUtil.showToast(this.context, "请输入您的新密码");
            return;
        }
        if (!UiUtil.isValidUserName(str2)) {
            UiUtil.showToast(this.context, "密码需要6~12位字符或数字");
            return;
        }
        ChangeMobile(str4, str2, str3, str1);
    }

    private void getToken() {
        HashMap localHashMap = new HashMap();
        localHashMap.put("grant_type", "client_credentials");
        RequestNet.postToken(this.context, AppConstants.URL_GETTOKEN, localHashMap, new StringCallback() {
            public void onError(Call paramAnonymousCall, Exception paramAnonymousException) {
                LogUtils.e(ForgetLoginPwdActivity.this.TAG, "获取失败,getParent2RoomListInfo-result:" + paramAnonymousException);
                ForgetLoginPwdActivity.this.setSureBtnIsEnable(true);
                ForgetLoginPwdActivity.this.dismissLoadingDialog();
                UiUtil.showToast(ForgetLoginPwdActivity.this.context, "找回失败");
            }

            public void onResponse(String paramAnonymousString) {
                Gson localGson = new Gson();
                try {
                    localTokenModel = (TokenModel) localGson.fromJson(paramAnonymousString, TokenModel.class);
                    if (localTokenModel == null) {
                        LogUtils.e(ForgetLoginPwdActivity.this.TAG, "获取失败");
                        ForgetLoginPwdActivity.this.dismissLoadingDialog();
                        ForgetLoginPwdActivity.this.setSureBtnIsEnable(true);
                        UiUtil.showToast(ForgetLoginPwdActivity.this.context, "找回失败");
                        return;
                    }
                } catch (Exception localException) {
                    do {
                        TokenModel localTokenModel;
                        do
                            while (true) {
                                localException.printStackTrace();
                                localTokenModel = null;
                            }
                        while (localTokenModel == null);
                        AppConstants.NO_LOGIN_TOKEN = localTokenModel.getAccess_token();
                    }
                    while (!ForgetLoginPwdActivity.this.mAction.equals("1"));
                    ForgetLoginPwdActivity.this.checkoutdata();
                }
            }
        });
    }

    private void getveriycode(String paramString1, String paramString2) {
        HashMap localHashMap = new HashMap();
        localHashMap.put("mobile", paramString1);
        localHashMap.put("user_name", paramString2);
        LogUtils.d(this.TAG, "URL:" + AppConstants.URL_GET_VERYPASSWORD);
        RequestNet.get(this.context, AppConstants.URL_GET_VERYPASSWORD, localHashMap, new StringCallback() {
            public void onError(Call paramAnonymousCall, Exception paramAnonymousException) {
                UiUtil.showToast(ForgetLoginPwdActivity.this.context, "找回失败");
                LogUtils.e(ForgetLoginPwdActivity.this.TAG, "请求失败,:" + paramAnonymousException);
            }

            public void onResponse(String paramAnonymousString) {
                LogUtils.d(ForgetLoginPwdActivity.this.TAG, "VeryPasswordBean数据" + paramAnonymousString);
                if (UiUtil.IsValueEmpty(paramAnonymousString))
                    LogUtils.d(ForgetLoginPwdActivity.this.TAG, "VeryPasswordBean为空时:" + paramAnonymousString);
                VeryPasswordBean localVeryPasswordBean;
                do {
                    return;
                    Gson localGson = new Gson();
                    try {
                        localVeryPasswordBean = (VeryPasswordBean) localGson.fromJson(paramAnonymousString, VeryPasswordBean.class);
                        if (localVeryPasswordBean == null) {
                            LogUtils.e(ForgetLoginPwdActivity.this.TAG, "veryPasswordBean == null，获取失败");
                            return;
                        }
                    } catch (Exception localException) {
                        while (true) {
                            localException.printStackTrace();
                            localVeryPasswordBean = null;
                        }
                        if (localVeryPasswordBean.getFlag() == 0) {
                            UiUtil.showToast(ForgetLoginPwdActivity.this.context, localVeryPasswordBean.getMsg());
                            return;
                        }
                        if (localVeryPasswordBean.getFlag() == -2) {
                            ForgetLoginPwdActivity.this.showDownWireDialog();
                            return;
                        }
                        if (localVeryPasswordBean.getFlag() == -3) {
                            ForgetLoginPwdActivity.this.ShowFengjinDialog();
                            return;
                        }
                        if (localVeryPasswordBean.getFlag() == -4) {
                            ForgetLoginPwdActivity.activityStack.backToMain(MainActivity.class, ForgetLoginPwdActivity.this.context);
                            return;
                        }
                    }
                }
                while (localVeryPasswordBean.getFlag() != 1);
                ForgetLoginPwdActivity.this.Daojishi();
                UiUtil.showToast(ForgetLoginPwdActivity.this.context, localVeryPasswordBean.getMsg());
            }
        });
    }

    private void setSureBtnIsEnable(boolean paramBoolean) {
        if (paramBoolean)
            this.img_sure.setBackgroundResource(2130838215);
        while (true) {
            this.img_sure.setEnabled(paramBoolean);
            return;
            this.img_sure.setBackgroundResource(2130838087);
        }
    }

    public void Daojishi() {
        if (this.isPause) {
            TimerTask local5 = new TimerTask() {
                public void run() {
                    ForgetLoginPwdActivity localForgetLoginPwdActivity = ForgetLoginPwdActivity.this;
                    localForgetLoginPwdActivity.timerRecord = (-1 + localForgetLoginPwdActivity.timerRecord);
                    if (ForgetLoginPwdActivity.this.timerRecord <= 0) {
                        ForgetLoginPwdActivity.this.timer.cancel();
                        ForgetLoginPwdActivity.this.timer = null;
                        ForgetLoginPwdActivity.this.handler.sendEmptyMessage(1);
                        return;
                    }
                    Message localMessage = ForgetLoginPwdActivity.this.handler.obtainMessage();
                    localMessage.what = 0;
                    localMessage.arg1 = ForgetLoginPwdActivity.this.timerRecord;
                    localMessage.sendToTarget();
                }
            };
            if (this.timer == null)
                this.timer = new Timer();
            this.timer.schedule(local5, 1000L, 1000L);
        }
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(2130903058);
        CustomApplication.app.addActivity(this);
        this.context = this;
        setTitle(8, 0, 2130837809, "找回密码", 0, 8, 8, 0, true);
        if (AppConstants.NO_LOGIN_TOKEN.equals(""))
            getToken();
        this.edit_user_phone_no = ((EditText) findViewById(2131099750));
        this.edit_user_phone_no.addTextChangedListener(this.textWatcher);
        this.edit_user_veriy_code = ((EditText) findViewById(2131099754));
        this.user_name = ((EditText) findViewById(2131099856));
        this.edit_new_loginpwd = ((EditText) findViewById(2131099857));
        this.img_sure = ((ImageView) findViewById(2131099756));
        this.img_sure.setOnClickListener(this.onClickListener);
        this.get_veriycode = ((Button) findViewById(2131099755));
        this.get_veriycode.setOnClickListener(this.onClickListener);
        this.get_veriycode.setBackgroundResource(2130837970);
        this.get_veriycode.setEnabled(false);
        this.myDialog1 = new MyDialog1(this.context);
    }

    protected void onDestroy() {
        super.onDestroy();
        if (this.mSMSBroadcastReceiver != null)
            unregisterReceiver(this.mSMSBroadcastReceiver);
    }

    protected void onPause() {
        super.onPause();
        closeWindowSoftInput(this.user_name);
        closeWindowSoftInput(this.edit_user_phone_no);
        closeWindowSoftInput(this.edit_user_veriy_code);
        closeWindowSoftInput(this.edit_new_loginpwd);
    }

    protected void onStart() {
        super.onStart();
        registerSMSReceiver();
        this.mSMSBroadcastReceiver.setOnReceivedMessageListener(new SMSBroadcastReceiver.MessageListener() {
            public void onReceived(String paramAnonymousString) {
                ForgetLoginPwdActivity.this.edit_user_veriy_code.setText(paramAnonymousString);
            }
        });
    }

    public void registerSMSReceiver() {
        if (this.mSMSBroadcastReceiver == null)
            this.mSMSBroadcastReceiver = new SMSBroadcastReceiver();
        IntentFilter localIntentFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
        localIntentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        localIntentFilter.setPriority(1000);
        registerReceiver(this.mSMSBroadcastReceiver, localIntentFilter);
    }

    @SuppressLint({"NewApi"})
    public void setTitle(int paramInt1, int paramInt2, int paramInt3, String paramString, int paramInt4, int paramInt5, int paramInt6, int paramInt7, boolean paramBoolean) {
        View localView = findViewById(2131099716);
        if (paramBoolean)
            localView.setVisibility(0);
        while (true) {
            ((TextView) localView.findViewById(2131099701)).setText(paramString);
            ((TextView) localView.findViewById(2131099700)).setVisibility(paramInt1);
            ImageView localImageView = (ImageView) localView.findViewById(2131099699);
            localImageView.setVisibility(paramInt2);
            localImageView.setOnClickListener(this.onClickListener);
            localImageView.setImageResource(paramInt3);
            TextView localTextView = (TextView) localView.findViewById(2131099702);
            localTextView.setVisibility(paramInt5);
            localTextView.setOnClickListener(this.onClickListener);
            this.iv_title_right = ((ImageView) localView.findViewById(2131099704));
            this.iv_title_right.setVisibility(paramInt6);
            this.iv_title_right.setOnClickListener(this.onClickListener);
            this.iv_title_right.setImageResource(paramInt7);
            return;
            localView.setVisibility(8);
        }
    }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.tabMine.ForgetLoginPwdActivity
 * JD-Core Version:    0.6.2
 */